using System;
using Entropy.Ext.Ast;

internal class Const : Node
{
    public readonly string Value;

    public Const(object value)
    {
        if (value == null)
            Value = "null";
        else if (value is bool)
            Value = value.ToString().ToLower();
        else if (value is Enum)
            Value = Quote(value.ToString().ToLower());
        else if (value is int || value is decimal || value is double)
            Value = value.ToString();
        else if (value is string)
            Value = Quote((string)value);
        else
            Value = null;
    }

    internal static string Quote(string s)
    {
        // Prepend new lines with \ to comply with javascript multiline quoting
        s = s.Replace(Environment.NewLine, @"\" + Environment.NewLine);
        return "'" + s + "'";
    }
}